// 管理mock数据，班级管理
import * as mUtils from '@/util/mUtils'
let classesRecord=[];                  //存储班级记录
const num=100;                       //模拟的班级信息数据总数
for(let i=1;i<=num;i++){
    classesRecord.push({
        classesId: i.toString(),         //班级id
        grade: '18级'.toString(),        //年级
        major: '专业'+i.toString(),       //专业
        number: i + "班".toString(),        //班号
    });
}
export default {
    //下拉获取所有年级
    getGrades:() => (
        {
            code: 1,
            msg: "获取成功",
            data: {
                data: ['17级', '18级', '19级', '20级']
            }
        }),
    getMajors:() => (
        {
            code: 1,
            msg: "获取专业成功",
            data: {
                data: ['专业1', '专业2', '专业3', '专业4', '专业5', '专业6']
            }
            }),
    getNumbers: () => (
        {
            code: 1,
            msg: "获取班级成功",
            data: {
                data: ['1班', '2班', '3班', '4班']
            }
            }),
    //获取班级信息列表
    getClasses: config => {
        const {currentPage, rows } = mUtils.param2Obj(config.url);
        const list = classesRecord.filter((item,index) => index < rows * currentPage && index >= rows * (currentPage - 1));
        return {
            data: {
                    data: list,
                    count: classesRecord.length,
            },
            code: 1,
            msg: '查询成功'
        }
    },
    //表格中删除指定班级
    deleteClasses:config=>{
        const {classesId} = mUtils.param2Obj(config.url);
        classesRecord=classesRecord.filter(item=>item.classesId!==classesId);
        return {
            data:{},
            code:1,
            msg:'删除班级成功'
        }
    },
    //查询班级
    queryClasses:config=>{
        const info = mUtils.param2ObjPost(config.body);
        const conlist = classesRecord.filter(item=>item.grade.includes(info['classRecord[grade]']))
            .filter(item=>item.major.includes(info['classRecord[major]']))
            .filter(item=>item.number.includes(info['classRecord[number]']));
        const list = conlist.filter((item,index) => index < info.rows * info.currentPage && index >= info.rows * (info.currentPage - 1))
        return {
            data:{
                data:list,
                count:conlist.length
            },
            code:1,
            msg:'查找班级成功'
        }
    },
    //添加班级
    addClasses:config=>{
        // classesId,
        const { grade,major,number } = mUtils.param2ObjPost(config.body);
        const info={
            classesId:(Math.floor(Math.random()*100)+100).toString(),
            grade:grade,
            major:major,
            number:number,
        };
        classesRecord.unshift(info);
        return {
            data:{},
            code:1,
            msg:'添加班级成功'
        }
    },

    batchDeleteClasses:config=>{
        let ids = mUtils.param2ObjPost(config.body);
        const num=[];
        for(let key in ids){
            num.push(ids[key])
        }
        classesRecord=classesRecord.filter(item=>!num.includes(item.classesId))
        return {
            data:{},
            code:1,
            msg:'批量删除班级成功'
        }
    },
}
